{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# -- coding: utf-8 --\n",
    "import turtle as t\n",
    "from turtle import *\n",
    "import random as r\n",
    "\n",
    "\n",
    "n = 100.0\n",
    "\n",
    "write_content = \"圣诞快乐！\"\n",
    "write_font = (\"Comic Sans MS\", 16, \"bold\")\n",
    "\n",
    "speed(100000)  # 定义速度\n",
    "pensize(5)  # 画笔宽度\n",
    "screensize(800, 800, bg='black')  # 定义背景颜色，可以自己换颜色\n",
    "left(90)\n",
    "forward(250)              # 开始的高度\n",
    "color(\"orange\", \"yellow\")  # 定义最上端星星的颜色，外圈是orange，内部是yellow\n",
    "begin_fill()\n",
    "left(126)\n",
    "\n",
    "\n",
    "# 画五角星\n",
    "for i in range(5):\n",
    "    forward(n / 5)\n",
    "    right(144)  # 五角星的角度\n",
    "    forward(n / 5)\n",
    "    left(72)  # 继续换角度\n",
    "end_fill()\n",
    "right(126)\n",
    "\n",
    "\n",
    "# 定义画彩灯的方法\n",
    "def drawlight():\n",
    "    if r.randint(0, 50) == 0:  # 如果觉得彩灯太多，可以把取值范围加大一些，对应的灯就会少一些\n",
    "        color('tomato')  # 定义第一种颜色\n",
    "        circle(3)  # 定义彩灯大小\n",
    "    elif r.randint(0, 30) == 1:\n",
    "        color('orange')  # 定义第二种颜色\n",
    "        circle(4)  # 定义彩灯大小\n",
    "    elif r.randint(0, 50) == 2:\n",
    "        color('blue')  # 定义第三种颜色\n",
    "        circle(2)  # 定义彩灯大小\n",
    "    elif r.randint(0, 30) == 3:\n",
    "        color('white')  # 定义第四种颜色\n",
    "        circle(4)  # 定义彩灯大小\n",
    "    else:\n",
    "        color('dark green')  # 其余的随机数情况下画空的树枝\n",
    "\n",
    "\n",
    "color(\"dark green\")  # 定义树枝的颜色\n",
    "backward(n * 4.8)\n",
    "\n",
    "# 画树\n",
    "def tree(d, s):\n",
    "    speed(100)\n",
    "    if d <= 0: return\n",
    "    forward(s)\n",
    "    tree(d - 1, s * .8)\n",
    "    right(120)\n",
    "    tree(d - 3, s * .5)\n",
    "    drawlight()  # 同时调用小彩灯的方法\n",
    "    right(120)\n",
    "    tree(d - 3, s * .5)\n",
    "    right(120)\n",
    "    backward(s)\n",
    "\n",
    "\n",
    "tree(15, 100)\n",
    "backward(50)\n",
    "\n",
    "\n",
    "# 循环画最底端的小装饰\n",
    "for i in range(200):\n",
    "    a = 200 - 400 * r.random()\n",
    "    b = 10 - 20 * r.random()\n",
    "    up()\n",
    "    forward(b)\n",
    "    left(90)\n",
    "    forward(a)\n",
    "    down()\n",
    "    if r.randint(0, 1) == 0:\n",
    "        color('tomato')\n",
    "    else:\n",
    "        color('wheat')\n",
    "    circle(2)\n",
    "    up()\n",
    "    backward(a)\n",
    "    right(90)\n",
    "    backward(b)\n",
    "\n",
    "\n",
    "# 画雪人 (n,m)是头和身子交点的坐标，a是头的大小，m是身体的大小\n",
    "def drawsnowman(n,m,a,b):\n",
    "    speed(100)\n",
    "    t.goto(n, m)\n",
    "    t.pencolor(\"white\")\n",
    "    t.pensize(2)\n",
    "    t.fillcolor(\"white\")\n",
    "    t.seth(0)\n",
    "    t.begin_fill()\n",
    "    t.circle(a)\n",
    "    t.end_fill()\n",
    "    t.seth(180)\n",
    "    t.begin_fill()\n",
    "    t.circle(b)\n",
    "    t.end_fill()\n",
    "    t.pencolor(\"black\")\n",
    "    t.fillcolor(\"black\")\n",
    "    t.penup()    # 右眼睛\n",
    "    t.goto(n-a/4, m+a)\n",
    "    t.seth(0)\n",
    "    t.pendown()\n",
    "    t.begin_fill()\n",
    "    t.circle(2)\n",
    "    t.end_fill()\n",
    "    t.penup()    # 左眼睛\n",
    "    t.goto(n+a/4, m+a)\n",
    "    t.seth(0)\n",
    "    t.pendown()\n",
    "    t.begin_fill()\n",
    "    t.circle(2)\n",
    "    t.end_fill()\n",
    "    t.penup()  # 画嘴巴\n",
    "    t.goto(n, m+a/2)\n",
    "    t.seth(0)\n",
    "    t.pendown()\n",
    "    t.fd(5)\n",
    "    t.penup()       # 画扣子\n",
    "    t.pencolor(\"red\")\n",
    "    t.fillcolor(\"red\")\n",
    "    t.goto(n, m-b/4)\n",
    "    t.pendown()\n",
    "    t.begin_fill()\n",
    "    t.circle(2)\n",
    "    t.end_fill()\n",
    "    t.penup()\n",
    "    t.pencolor(\"yellow\")\n",
    "    t.fillcolor(\"yellow\")\n",
    "    t.goto(n, m-b/2)\n",
    "    t.pendown()\n",
    "    t.begin_fill()\n",
    "    t.circle(2)\n",
    "    t.end_fill()\n",
    "    t.penup()\n",
    "    t.pencolor(\"orange\")\n",
    "    t.fillcolor(\"orange\")\n",
    "    t.goto(n, m-(3*b)/4)\n",
    "    t.pendown()\n",
    "    t.begin_fill()\n",
    "    t.circle(2)\n",
    "    t.end_fill()\n",
    "\n",
    "drawsnowman(-200, -200, 20, 30)\n",
    "drawsnowman(-250, -200, 30, 40)\n",
    "\n",
    "t.up()\n",
    "t.goto(100, 200)\n",
    "t.down()\n",
    "t.color(\"dark red\", \"red\")  # 定义字体颜色\n",
    "t.penup()\n",
    "t.write(write_content, font=write_font)  # 定义文字、位置、字体、大小\n",
    "t.end_fill()\n",
    "\n",
    "\n",
    "# 画雪花\n",
    "def drawsnow():\n",
    "    t.ht()  # 隐藏笔头，ht=hideturtle\n",
    "    t.pensize(2)  # 定义笔头大小\n",
    "    for i in range(200):  # 画多少雪花\n",
    "        t.pencolor(\"white\")  # 定义画笔颜色为白色，其实就是雪花为白色\n",
    "        t.pu()  # 提笔，pu=penup\n",
    "        t.setx(r.randint(-350, 350))  # 定义x坐标，随机从-350到350之间选择\n",
    "        t.sety(r.randint(-100, 350))  # 定义y坐标，注意雪花一般在地上不会落下，所以不会从太小的纵座轴开始\n",
    "        t.pd()  # 落笔，pd=pendown\n",
    "        dens = 6  # 雪花瓣数设为6\n",
    "        snowsize = r.randint(1, 10)  # 定义雪花大小\n",
    "        for j in range(dens):  # 就是6，那就是画5次，也就是一个雪花五角星\n",
    "            # t.forward(int(snowsize))  #int（）取整数\n",
    "            t.fd(int(snowsize))\n",
    "            t.backward(int(snowsize))\n",
    "            # t.bd(int(snowsize))  #注意没有bd=backward，但有fd=forward，小bug\n",
    "            t.right(int(360 / dens))  # 转动角度\n",
    "\n",
    "\n",
    "drawsnow()  # 调用画雪花的方法\n",
    "t.done()  # 完成,否则会直接关闭\n",
    "from turtle import *\n",
    "import time\n",
    "\n",
    "setup(500, 500, startx=None, starty=None)\n",
    "speed(0)\n",
    "pencolor(\"pink\")\n",
    "pensize(10)\n",
    "penup()\n",
    "hideturtle()\n",
    "goto(0, 150)\n",
    "showturtle()\n",
    "pendown()\n",
    "shape(name=\"classic\")\n",
    "# 1\n",
    "seth(-120)\n",
    "for i in range(10):\n",
    "    fd(12)\n",
    "    right(2)\n",
    "penup()\n",
    "goto(0, 150)\n",
    "seth(-60)\n",
    "pendown()\n",
    "for i in range(10):\n",
    "    fd(12)\n",
    "    left(2)\n",
    "seth(-150)\n",
    "penup()\n",
    "fd(10)\n",
    "pendown()\n",
    "for i in range(5):\n",
    "    fd(10)\n",
    "    right(15)\n",
    "seth(-150)\n",
    "penup()\n",
    "fd(8)\n",
    "pendown()\n",
    "for i in range(5):\n",
    "    fd(10)\n",
    "    right(15)\n",
    "seth(-155)\n",
    "penup()\n",
    "fd(5)\n",
    "pendown()\n",
    "for i in range(5):\n",
    "    fd(7)\n",
    "    right(15)\n",
    "# 2\n",
    "penup()\n",
    "goto(-55, 34)\n",
    "pendown()\n",
    "seth(-120)\n",
    "for i in range(10):\n",
    "    fd(8)\n",
    "    right(5)\n",
    "\n",
    "penup()\n",
    "goto(50, 35)\n",
    "seth(-60)\n",
    "pendown()\n",
    "for i in range(10):\n",
    "    fd(8)\n",
    "    left(5)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
